# -*- coding: utf-8 -*-

class RTSPUtil:

    def __init__(self, ip, username, password):
        self.ip = ip
        self.username = username
        self.password = password

        # 海康：rtsp://admin:pg123456@192.168.1.37:554/h264/ch1/sub/av_stream
        # 雄迈：rtsp://192.168.1.218:554/user=admin&password=&channel=1&stream=0.sdp?real_stream

    def capture(self):
        """
        抓图操作
        :return:
        """
        # rtsp_url = 'rtsp://' + self.username + ':' + self.password + '@' + self.ip + ':554/h264/ch1/sub/av_stream'
        # # rtsp_url = 0
        # try:
        #     ret, image = cv2.VideoCapture(rtsp_url).read()
        #     #  VideoCapture()中：参数是0，表示打开笔记本的内置摄像头；参数是1，则打开外置摄像头；其他数字则代表其他设备；
        #     #  参数是视频文件的路径则打开指定路径下的视频。
        #
        #     while image is []:
        #         ret, image = cv2.VideoCapture(rtsp_url).read()
        #     while image is None:
        #         print('snap again')
        #         ret, image = cv2.VideoCapture(rtsp_url).read()
        #     return image
        # except Exception as e:
        #     print('snap error')
        pass


if __name__ == '__main__':
    rtsp = RTSPUtil('192.168.1.218', 'admin', 'admin')

    while True:
        frame = rtsp.capture()
        # cv2.imshow("frame", frame)
        # cv2.waitKey(10)
